package com.i8office.android.zhihuixinwu.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cyan.tools.base.BaseViewHolder;
import com.cyan.tools.base.RecyclerArrayAdapter;
import com.example.menhoo.toollibrary.common.utils.DisplayUtil;
import com.i8office.android.zhihuixinwu.R;
import com.i8office.android.zhihuixinwu.ui.schedule.ScheduleDateTask;
import com.i8office.android.zhihuixinwu.ui.schedule.ScheduleTask;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by pc on 2018/7/8.
 */

public class ScheduleByDateAdapter extends RecyclerArrayAdapter<ScheduleDateTask> {
    private Context mContext;

    public ScheduleByDateAdapter(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(parent);
    }

    class ViewHolder extends BaseViewHolder<ScheduleDateTask> {
        @BindView(R.id.location)
        TextView location;
        @BindView(R.id.department)
        TextView department;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.people)
        TextView people;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.content)
        View content;

        public ViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_event_by_date);
            ButterKnife.bind(this, itemView);
            setDrawableLeft(location, R.drawable.icon_location);
            setDrawableLeft(department, R.drawable.icon_department);
            setDrawableLeft(people, R.drawable.icon_group_people);
        }

        @Override
        public void setData(final ScheduleDateTask task) {
            people.setText(task.getLerderName());
            content.setVisibility(TextUtils.isEmpty(task.getTitle()) ? View.GONE : View.VISIBLE);
            location.setText(task.getLocation());
            location.setVisibility(TextUtils.isEmpty(task.getLocation()) ? View.GONE : View.VISIBLE);
            department.setText(task.getDeptName());
            department.setVisibility(TextUtils.isEmpty(task.getDeptName()) ? View.GONE : View.VISIBLE);
            title.setText(task.getTitle());
            time.setText(TextUtils.isEmpty(task.getStartTime()) ? "-- : --" : task.getStartTime12());
        }
    }

    private void setDrawableLeft(TextView view, @DrawableRes int drawableRes) {
        Drawable drawable = ContextCompat.getDrawable(mContext, drawableRes);
        drawable.setBounds(0, 0, DisplayUtil.dip2px(mContext, 12), DisplayUtil.dip2px(mContext, 12));
        view.setCompoundDrawables(drawable, null, null, null);
    }

}
